package com.czy.owner.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.czy.owner.R;
import com.czy.owner.entity.HotCarProductEntity;
import com.czy.owner.utils.glide.GlideUtils;
import com.easyrecycleview.adapter.BaseViewHolder;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;


/**
 * Created by wangyang on 2017/5/18 0018.
 */

public class HotCarProductAdapter extends RecyclerArrayAdapter<HotCarProductEntity> {

    private Context context;

    public HotCarProductAdapter(Context context) {
        super(context);
        this.context = context;
    }


    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new HotCarViewHolder(parent);
    }

    class HotCarViewHolder extends BaseViewHolder<HotCarProductEntity> {
        private ImageView ivGoodsImg;
        private ImageView ivSellOut;
        private TextView tvGoodsName;
        private TextView tvGoodsPrice;
        private TextView tvGoodsDescrtion;

        public HotCarViewHolder(ViewGroup parent) {
            super(parent, R.layout.item_hot_car_product_recycler);
            ivGoodsImg = $(R.id.iv_goods_img);
            ivSellOut = $(R.id.iv_sell_out);
            tvGoodsName = $(R.id.tv_goods_name);
            tvGoodsPrice = $(R.id.tv_goods_price);
            tvGoodsDescrtion = $(R.id.tv_goods_descrtion);

        }


        @Override
        public void setData(final HotCarProductEntity data) {
            super.setData(data);
            int totalCount = data.getTotalCount();
            int currentCount = data.getCurrentCount();
            int salesNum = data.getSalesNum();
            tvGoodsName.setText(data.getGoodsName());
            tvGoodsPrice.setText("￥" + String.format("%.2f", data.getPrice()));
            tvGoodsDescrtion.setText(context.getResources().getString(R.string.goods_descrtion, salesNum, "件", data.getComments()));
//            if (currentCount == 0) {
//                ivSellOut.setVisibility(View.VISIBLE);
//            } else {
//                ivSellOut.setVisibility(View.GONE);
//            }
            GlideUtils.loadImage(context, data.getLogo(), ivGoodsImg, new GlideUtils.ImageLoadListener<String, GlideDrawable>() {
                @Override
                public void onLoadingComplete(String uri, ImageView view, GlideDrawable resource) {

                }

                @Override
                public void onLoadingError(String source, Exception e) {

                }
            }, R.mipmap.default_icon, R.mipmap.default_icon);
        }
    }


}
